import { Controller, Get, Param, ParseIntPipe, Post, Query, SetMetadata, UseGuards } from "@nestjs/common";
import { LogService } from './log.service';
import { GetLogDto } from '@/modules/log/dto/log.dto';
import { RequireLogin, RequirePermission, UserInfo } from '@/common/decorators/custom.decorator';
import { AuthGuard } from "@nestjs/passport";

@Controller('userlogs')
export class LogController {
  constructor(private readonly logService: LogService) {
  }

  @Get('test')
  async test() {
    throw new Error('系统日志报错');
  }

  //查询所有
  @UseGuards(AuthGuard('jwt'))
  @Get('/list')
  async getLogsByPage(@Query() queryDto: GetLogDto,@UserInfo('username') username:string,@UserInfo() userInfo:any) {
    console.log('username:',username);
    console.log('userInfo:',userInfo);
    return this.logService.getLogsByPage(queryDto);
  }

  //删除所有日志
  @Post('/deleteAll')
  async deleteAllLogs() {
    return this.logService.deleteAllLogs();
  }

  //获取单个日志
  @Get(':id')
  async getLog(@Param('id', ParseIntPipe) id: number) {
    return this.logService.getLog(id);
  }

  //删除单个日志
  @Post('/delete/:id')
  async deleteLog(@Param('id', ParseIntPipe) id: number) {
    return this.logService.deleteLog(id);
  }
}
